package com.gec.controller;

import com.gec.dao.OptionDao;
import com.gec.domain.Option;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Option")
public class OptionController extends BaseController {
    private final OptionDao optionDao;

    public OptionController(OptionDao optionDao) {
        this.optionDao = optionDao;
    }

    @RequestMapping(
            value = "/getRole",
            produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getRole() {
        List<Option> options;
        try {
            options = optionDao.getRoleOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }

    @RequestMapping(
            value = "/getRoomType",
            produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getRoomType() {
        List<Option> options;
        try {
            options = optionDao.getRoomTypeOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());

        }
    }

    @RequestMapping( value = "/getStorey",produces = HTML)
    @ResponseBody
    public String getStorey() {
        List<Option> options;
        try {
            options = optionDao.getStoreyOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }


    @RequestMapping(value = "/getDept",produces = HTML)
    @ResponseBody
    public String getDept() {
        List<Option> options;
        try {
            options = optionDao.getDeptOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }


    @RequestMapping(value = "/getMenu", produces = HTML)
    @ResponseBody
    public String getMenu() {
        List<Option> options;
        try {
            options = optionDao.getMenuOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }

    @RequestMapping(value = "/getRoleName", produces = HTML)
    @ResponseBody
    public String getRoleName() {
        List<Option> options;
        try {
            options = optionDao.getRoleNameOptions();
            System.out.println(options);
            return sendData(options);
        } catch (Exception e) {
            e.printStackTrace();
            return sendError(e.getMessage());
        }
    }

}
